class Node {
    constructor(e) {
        this.element = e;
        this.next = null;
        this.prev = null
    }
};
class DoublyLinkedList {
    constructor() {
        this.head = new Node('head');
    };
    find() {
        let currNode = this.head;
        while (currNode.element != item) {
            currNode = currNode.next;
        };
        return currNode
    };
    findLast() {
        let currNode = this.head;
        while (currNode.next != null) {
            currNode = currNode.next;
        };
        return currNode
    };
    insert(newElement, item) {
        let newNode = new Node(newElement);
        let currNode = this.find(item);
        newNode.next = currNode.next;
        currNode.next.prev = newNode;
        newNode.prev = currNode;
        currNode.next = newNode
    };
    remove(item) {
        let currNode = this.find(item);
        if (currNode.next != null && currNode.next.element != item) {
            currNode.prev.next = currNode.next;
            currNode.next.prev = currNode.prev;
            currNode.next = null;
            currNode.prev = null
        }
    };
    display() {
        let currNode = this.head;
        while (currNode.next != null) {
            console.log(currNode.next.element);
            currNode = currNode.next;
        }
    };
    reverseDisplay() {
        let currNode = this.findLast();
        while (currNode.prev != null) {
            console.log(currNode.element);
            currNode = currNode.prev
        }
    }
}